#导入模块
import json
import os

#定义菜品文件路径
DISHES_FILE_PATH = "data/dishes.json"

def load_all_dishes_from_file():
    if not os.path.exists(DISHES_FILE_PATH):
        return []
    try:
        with open(DISHES_FILE_PATH, "r", encoding="utf-8") as file:
            return json.load(file)
    except json.JSONDecodeError:
        print("警告：JSON文件格式错误，已加载为空列表！")
        return []

#将所有菜品保存到文件并打开文件并写入内容
def save_all_dishes_to_file(all_dishes_list):
    with open(DISHES_FILE_PATH, "w", encoding="utf-8") as file:
        json.dump(all_dishes_list, file, ensure_ascii=False, indent=4)